import {
    getUserData
} from "@/utils/IndexedDB.js";

async function checkPermission(el) {
    const res = await getUserData("userBase", "infoBase", 0);
    if (Number(res.userAuthority) !== 0) {
        el.parentNode && el.parentNode.removeChild(el)
    }
}

// export default function hasPermission(Vue) {
//     const install = function (Vue) {
//         Vue.directive('permission', {
//             inserted(el, binding) {
//                 checkPermission(el, binding)
//             },
//             update(el, binding) {
//                 checkPermission(el, binding)
//             }
//         })
//     }
//     Vue.use(install)
// }

export default {
    install: function (Vue, options) {
        Vue.directive('permission', {
            inserted(el, binding) {
                checkPermission(el, binding)
            },
            update(el, binding) {
                checkPermission(el, binding)
            }
        })

    }
}